{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ffefc9e1",
   "metadata": {},
   "source": [
    "![这是图片](./图片/batman.jpg \"test\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9ede9ea3",
   "metadata": {},
   "source": [
    "- 将十进制转化为二进制"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "81e8206d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "二进制的x：0b1100100\n"
     ]
    }
   ],
   "source": [
    "x = 100\n",
    "bin_x = bin(100)\n",
    "print(f'二进制的x：{bin_x}')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bfbdb296",
   "metadata": {},
   "source": [
    "---\n",
    "- next()的使用："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "838da773",
   "metadata": {},
   "outputs": [],
   "source": [
    "from collections import Counter\n",
    "def mostCommonWord(paragraph, banned):\n",
    "    ban = set(banned)\n",
    "    freq = Counter()\n",
    "    word, n = \"\", len(paragraph)\n",
    "    for i in range(n + 1):\n",
    "        if i < n and paragraph[i].isalpha():\n",
    "            word += paragraph[i].lower()\n",
    "        elif word:\n",
    "            if word not in ban:\n",
    "                freq[word] += 1\n",
    "            word = \"\"\n",
    "    maxFreq = max(freq.values())\n",
    "    print(f'type:{type(word for word, f in freq.items() if f == maxFreq)}')\n",
    "    ans = next(word for word, f in freq.items() if f == maxFreq)\n",
    "    fun = next(word for word, f in freq.items() if f == maxFreq)\n",
    "    return ans, fun"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "712a486e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "type:<class 'generator'>\n"
     ]
    }
   ],
   "source": [
    "paragraph = \"Bob hit a ball, the hit BALL flew far after it was hit. mother, mother\"\n",
    "banned = [\"hit\"]\n",
    "ans, fun = mostCommonWord(paragraph, banned)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "f288933d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ans, fun:('ball', 'ball')\n"
     ]
    }
   ],
   "source": [
    "print(f'ans, fun:{ans, fun}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3ddccbd1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
